package com.aphrodite.io.sip.net;

/**
 * IpAddress is an IP address.
 */
public final class IpAddress {

	/** Gets the IpAddress for a given fully-qualified host name. */
	public static IpAddress getByName(String host_addr) throws java.io.IOException {
		return new IpAddress(host_addr);
	}

	// ********************** Public ***********************

	/** Detects the default IP address of this host. */
	public static IpAddress getLocalHostAddress() {
		return new IpAddress("127.0.0.1");
	}

	/** The host address/name */
	private String address;

	/** Creates an IpAddress */
	public IpAddress(IpAddress ipaddr) {
		this(ipaddr.address);
	}

	/** Creates an IpAddress */
	public IpAddress(String address) {
		this.address = address;
	}

	/** Makes a copy */
	public Object clone() {
		return new IpAddress(this);
	}

	// *********************** Static ***********************

	/** Wthether it is equal to Object <i>obj</i> */
	public boolean equals(Object obj) {
		try {
			IpAddress ipaddr = (IpAddress) obj;
			if (!toString().equals(ipaddr.toString()))
				return false;
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	/** Gets a String representation of the Object */
	public String toString() {
		return address;
	}

}